In [50]:
!pip install plotly
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as ml
import seaborn as sns
import plotly
import plotly.plotly as py
import warnings
from scipy import stats
warnings.filterwarnings('ignore')
Requirement already satisfied: plotly in /Users/hclin/anaconda3/lib/python3.7/site-packages (3.7.1)
Requirement already satisfied: nbformat>=4.2 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from plotly) (4.4.0)
Requirement already satisfied: retrying>=1.3.3 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from plotly) (1.3.3)
Requirement already satisfied: six in /Users/hclin/anaconda3/lib/python3.7/site-packages (from plotly) (1.12.0)
Requirement already satisfied: requests in /Users/hclin/anaconda3/lib/python3.7/site-packages (from plotly) (2.21.0)
Requirement already satisfied: decorator>=4.0.6 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from plotly) (4.3.0)
Requirement already satisfied: pytz in /Users/hclin/anaconda3/lib/python3.7/site-packages (from plotly) (2018.7)
Requirement already satisfied: ipython-genutils in /Users/hclin/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (0.2.0)
Requirement already satisfied: jupyter-core in /Users/hclin/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (4.4.0)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (2.6.0)
Requirement already satisfied: traitlets>=4.1 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (4.3.2)
Requirement already satisfied: idna<2.9,>=2.5 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from requests->plotly) (2.8)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from requests->plotly) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from requests->plotly) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /Users/hclin/anaconda3/lib/python3.7/site-packages (from requests->plotly) (2018.11.29)
In [2]:
py.sign_in('hungChun', 'DiEL63Ss8uTCK0kvFF2z')
print(plotly.__version__)
3.7.1
In [3]:
#Suicide data
sd = pd.read_csv('suicide.csv', index_col = 0, encoding='latin')
sd.head(10)
Out[3]:
year sex age suicides_no population suicides/100k pop
country
Albania 1987 male 15-24 years 21 312900 6.71
Albania 1987 male 35-54 years 16 308000 5.19
Albania 1987 female 15-24 years 14 289700 4.83
Albania 1987 male 75+ years 1 21800 4.59
Albania 1987 male 25-34 years 9 274300 3.28
Albania 1987 female 75+ years 1 35600 2.81
Albania 1987 female 35-54 years 6 278800 2.15
Albania 1987 female 25-34 years 4 257200 1.56
Albania 1987 male 55-74 years 1 137500 0.73
Albania 1987 female 05-14 years 0 311000 0.00
In [4]:
#Group data by age gender of each year
gsd=pd.DataFrame(sd.groupby(['age','sex','year'])['suicides_no'].sum().unstack())
gsd = gsd.fillna(0)
gsd
Out[4]:
year 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 ... 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
age sex
05-14 years female 351.0 303.0 271.0 244.0 308.0 384.0 379.0 455.0 479.0 475.0 ... 585.0 628.0 724.0 675.0 748.0 608.0 719.0 761.0 693.0 0.0
male 633.0 641.0 664.0 593.0 842.0 1093.0 1154.0 1232.0 1310.0 1285.0 ... 1086.0 1012.0 1111.0 1085.0 1131.0 1144.0 1087.0 1121.0 988.0 0.0
15-24 years female 4690.0 4821.0 4046.0 3447.0 4004.0 5308.0 5034.0 5448.0 5181.0 5372.0 ... 5876.0 6163.0 6371.0 6164.0 6468.0 5940.0 5666.0 5452.0 5029.0 238.0
male 13180.0 13242.0 12386.0 11890.0 14632.0 17940.0 18283.0 19279.0 20081.0 21924.0 ... 21794.0 21982.0 22116.0 21520.0 21469.0 20340.0 18583.0 18576.0 16812.0 957.0
25-34 years female 4894.0 5058.0 4923.0 4468.0 5422.0 6772.0 6486.0 6830.0 6812.0 6846.0 ... 7254.0 7387.0 7596.0 7363.0 7437.0 7080.0 6719.0 6871.0 6265.0 373.0
male 15877.0 16627.0 17386.0 16864.0 24005.0 28504.0 29129.0 30928.0 32232.0 34100.0 ... 30682.0 30369.0 31793.0 30954.0 30499.0 29545.0 28349.0 28510.0 25853.0 1697.0
35-54 years female 9476.0 10047.0 10551.0 10014.0 12246.0 14622.0 14824.0 15840.0 15947.0 16238.0 ... 17989.0 18408.0 18751.0 18468.0 18344.0 17986.0 17524.0 17424.0 15876.0 1232.0
male 26272.0 27511.0 30098.0 28756.0 41295.0 50620.0 53550.0 59211.0 64723.0 68748.0 ... 67760.0 68256.0 71639.0 68896.0 67001.0 64496.0 62703.0 61708.0 55422.0 4534.0
55-74 years female 9057.0 9308.0 10373.0 9869.0 12727.0 14891.0 14887.0 15129.0 15288.0 15129.0 ... 14004.0 13878.0 14216.0 14297.0 14227.0 14071.0 13810.0 13926.0 12881.0 1119.0
male 19679.0 20452.0 22096.0 20669.0 27360.0 32127.0 33428.0 36377.0 38990.0 41447.0 ... 42853.0 43809.0 45686.0 45446.0 44951.0 44372.0 43886.0 43770.0 40707.0 3596.0
75+ years female 4011.0 4315.0 4842.0 4973.0 6654.0 8141.0 8012.0 7865.0 7624.0 7472.0 ... 7616.0 7509.0 7262.0 7255.0 7392.0 7326.0 7021.0 7122.0 6504.0 542.0
male 7943.0 8345.0 9206.0 9239.0 10749.0 12959.0 12854.0 12879.0 12898.0 13027.0 ... 15909.0 16046.0 16222.0 16579.0 16817.0 17252.0 17132.0 17743.0 16610.0 1315.0

12 rows × 32 columns

In [5]:
#Group data by age of each year
gsdtt=pd.DataFrame(sd.groupby(['age','year'])['suicides_no'].sum().unstack())
gsdtt = gsdtt.fillna(0)
gsdtt
Out[5]:
year 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 ... 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
age
05-14 years 984.0 944.0 935.0 837.0 1150.0 1477.0 1533.0 1687.0 1789.0 1760.0 ... 1671.0 1640.0 1835.0 1760.0 1879.0 1752.0 1806.0 1882.0 1681.0 0.0
15-24 years 17870.0 18063.0 16432.0 15337.0 18636.0 23248.0 23317.0 24727.0 25262.0 27296.0 ... 27670.0 28145.0 28487.0 27684.0 27937.0 26280.0 24249.0 24028.0 21841.0 1195.0
25-34 years 20771.0 21685.0 22309.0 21332.0 29427.0 35276.0 35615.0 37758.0 39044.0 40946.0 ... 37936.0 37756.0 39389.0 38317.0 37936.0 36625.0 35068.0 35381.0 32118.0 2070.0
35-54 years 35748.0 37558.0 40649.0 38770.0 53541.0 65242.0 68374.0 75051.0 80670.0 84986.0 ... 85749.0 86664.0 90390.0 87364.0 85345.0 82482.0 80227.0 79132.0 71298.0 5766.0
55-74 years 28736.0 29760.0 32469.0 30538.0 40087.0 47018.0 48315.0 51506.0 54278.0 56576.0 ... 56857.0 57687.0 59902.0 59743.0 59178.0 58443.0 57696.0 57696.0 53588.0 4715.0
75+ years 11954.0 12660.0 14048.0 14212.0 17403.0 21100.0 20866.0 20744.0 20522.0 20499.0 ... 23525.0 23555.0 23484.0 23834.0 24209.0 24578.0 24153.0 24865.0 23114.0 1857.0

6 rows × 32 columns

In [6]:
#Total suicide number by year
Tgsdtt = gsdtt.T
Tgsdtt.ix[:,:].plot(kind='bar',stacked = True, figsize=(10,6))
plt.legend(bbox_to_anchor=(1,1), title = 'Age group')
plt.title('Suicide number by year')
plt.xlabel('Year')
plt.ylabel('Suicide number')
Out[6]:
Text(0, 0.5, 'Suicide number')
In [7]:
#male
gsdm = pd.DataFrame(gsd.iloc[[1,3,5,7,9,11],:])
gsdm

#female
gsdf = pd.DataFrame(gsd.iloc[[0,2,4,6,8,10],:])
gsdf
Out[7]:
year 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 ... 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
age sex
05-14 years female 351.0 303.0 271.0 244.0 308.0 384.0 379.0 455.0 479.0 475.0 ... 585.0 628.0 724.0 675.0 748.0 608.0 719.0 761.0 693.0 0.0
15-24 years female 4690.0 4821.0 4046.0 3447.0 4004.0 5308.0 5034.0 5448.0 5181.0 5372.0 ... 5876.0 6163.0 6371.0 6164.0 6468.0 5940.0 5666.0 5452.0 5029.0 238.0
25-34 years female 4894.0 5058.0 4923.0 4468.0 5422.0 6772.0 6486.0 6830.0 6812.0 6846.0 ... 7254.0 7387.0 7596.0 7363.0 7437.0 7080.0 6719.0 6871.0 6265.0 373.0
35-54 years female 9476.0 10047.0 10551.0 10014.0 12246.0 14622.0 14824.0 15840.0 15947.0 16238.0 ... 17989.0 18408.0 18751.0 18468.0 18344.0 17986.0 17524.0 17424.0 15876.0 1232.0
55-74 years female 9057.0 9308.0 10373.0 9869.0 12727.0 14891.0 14887.0 15129.0 15288.0 15129.0 ... 14004.0 13878.0 14216.0 14297.0 14227.0 14071.0 13810.0 13926.0 12881.0 1119.0
75+ years female 4011.0 4315.0 4842.0 4973.0 6654.0 8141.0 8012.0 7865.0 7624.0 7472.0 ... 7616.0 7509.0 7262.0 7255.0 7392.0 7326.0 7021.0 7122.0 6504.0 542.0

6 rows × 32 columns

In [8]:
#Suicide population for male
for i in range(1985,2016):
    gsdm.ix[:,i].plot(kind='bar', color = ('skyblue'))
    plt.xticks(range(6),['15-24 years','25-34 years', '35-54 years', '5-14 years', '55-74 years', '75+ years'],
               rotation = 60)
    plt.xlabel('Age group')
    plt.ylabel('Suicide number')
    plt.title('Suicide population of male in '+ str(i))
    
    plt.show()
In [9]:
#Suicide population for female
for i in range(1985,2016):
    gsdf.ix[:,i].plot(kind='bar', color = ('lightpink'))
    plt.xticks(range(6),['15-24 years','25-34 years', '35-54 years', '5-14 years', '55-74 years', '75+ years'],rotation = 60)
    plt.xlabel('Age group')
    plt.ylabel('Suicide number')
    plt.title('Suicide population of female in'+ str(i))
    
    plt.show()
In [20]:
#Total number by age group
gsd02=pd.DataFrame(sd.groupby(['age','sex'])['suicides_no'].sum().unstack())
gsd02
gsd02_02 = pd.DataFrame(gsd02.T.sum())
gsd02_02
Out[20]:
0
age
05-14 years 52264
15-24 years 808542
25-34 years 1123912
35-54 years 2452141
55-74 years 1658443
75+ years 653118
In [21]:
#Pie chart by age group

age=['05-14 years','15-24 years','25-34 years','35-54 years','55-74 years','75+ years']
plt.pie(gsd02_02,
               labels = age,
               autopct = '%.1f%%',
               startangle =0,
               radius = 1.5,
               frame = 0,
               center = (4.5,4.5),
               explode=(0.2,0.1,0,0,0,0),
               shadow=True
               )
plt.show()
In [22]:
#Total by gender
sexsum = gsd02
sexsum = pd.DataFrame(sexsum.sum())
sexsum = sexsum.reset_index()
sexsum
Out[22]:
sex 0
0 female 1559510
1 male 5188910
In [24]:
#Compare the suicide number of male and female
gsd02.ix[:,1].plot(kind='bar', color='skyblue', width = 1, figsize=(8,5))
gsd02.ix[:,0].plot(kind='bar', color='lightpink', width = 1, alpha = 0.8,figsize=(8,5))
plt.ylabel('Suicide number')
plt.xlabel('Age group')
plt.xticks(rotation = 60)
plt.title('Suicide number')
plt.legend(['Male','Female'], bbox_to_anchor=(1, 1),title = 'Sex')
plt.show()
In [25]:
#Plot by year (line)
gsd_year=pd.DataFrame(sd.groupby(['year','country'])['suicides_no'].sum().unstack())
gsd_year = gsd_year.fillna(0)
gsd_year['Suicide number'] = gsd_year.sum(axis=1)

gsd_year.ix[:,'Suicide number'].plot(kind='line',figsize=(10,6),marker='o')
plt.title('Suicide number from 1985 to 2016')
plt.xlabel('year')
plt.ylabel('suicide number')
plt.show()
In [26]:
#Group data by country (absolute)
gsdcountry= (pd.DataFrame(sd.groupby(['country','sex'])['suicides_no'].sum().unstack()))/1000000
gsdcountry['Suicide number']=gsdcountry.apply(lambda gsdcountry: gsdcountry['female']+gsdcountry['male'], axis = 1)
gsdcountry = gsdcountry.sort_values(by='Suicide number',ascending=False)
gsdcountry.head(10)

gsdcountry.ix[0:10,2].plot(kind='barh')
plt.ylabel('Country')
plt.xlabel('Suicide number (million)')
plt.title('Top 10 country of suicide from 1987-2016')

plt.show()
In [27]:
#Original suicide number data
gsdcountrynormal = gsdcountry*1000000
gsdcountrynormal = pd.DataFrame(gsdcountrynormal['Suicide number'])
gsdcountrynormal = gsdcountrynormal.reset_index()
gsdcountrynormal
Out[27]:
country Suicide number
0 Russian Federation 1209742.0
1 United States 1034013.0
2 Japan 806902.0
3 France 329127.0
4 Ukraine 319950.0
5 Germany 291262.0
6 Republic of Korea 261730.0
7 Brazil 226613.0
8 Poland 139098.0
9 United Kingdom 136805.0
10 Italy 132060.0
11 Mexico 111139.0
12 Thailand 110643.0
13 Canada 107561.0
14 Kazakhstan 101546.0
15 Spain 100202.0
16 Argentina 82219.0
17 Hungary 73891.0
18 Romania 72777.0
19 Australia 70111.0
20 Belgium 62761.0
21 Belarus 59892.0
22 Sri Lanka 55641.0
23 Colombia 53080.0
24 Netherlands 50833.0
25 Austria 50073.0
26 Czech Republic 43687.0
27 Cuba 41418.0
28 Chile 40895.0
29 Sweden 37795.0
... ... ...
71 Azerbaijan 1656.0
72 Iceland 1108.0
73 Kuwait 966.0
74 United Arab Emirates 622.0
75 Malta 585.0
76 Qatar 574.0
77 Montenegro 472.0
78 Bahrain 463.0
79 Mongolia 423.0
80 Cyprus 412.0
81 Belize 348.0
82 Bosnia and Herzegovina 318.0
83 Fiji 304.0
84 Saint Lucia 230.0
85 Jamaica 184.0
86 Barbados 177.0
87 Saint Vincent and Grenadines 124.0
88 Aruba 101.0
89 Seychelles 98.0
90 Bahamas 93.0
91 Kiribati 53.0
92 Cabo Verde 42.0
93 Grenada 38.0
94 Oman 33.0
95 Macau 27.0
96 Maldives 20.0
97 Antigua and Barbuda 11.0
98 San Marino 4.0
99 Saint Kitts and Nevis 0.0
100 Dominica 0.0

101 rows × 2 columns

In [28]:
#Draw a choropleth map of world to show the suicide numnber by country
plotly.offline.init_notebook_mode()

#data to graph
my_data = [dict(type='choropleth', 
        autocolorscale=True,
        locations=gsdcountrynormal['country'],
        z=gsdcountrynormal['Suicide number'].astype(float),
        locationmode='country names',
        text=gsdcountrynormal['country'],
        hoverinfo='location+z',
        marker=dict(line=dict(color='rgb(180,180,180)',width=0.5)),
        colorbar=dict(title='Suicide number'))]

#layout
my_layout = dict(title='Suicide number',
                 geo=dict(scope='world',
                          projection=dict(type='mercator'),
                          showcoastlines= False,
                          showframe= False))

fig = dict(data=my_data, layout=my_layout)
py.iplot(fig, validata=False, filename='Suicide number')
Out[28]:
In [30]:
#Group data by country (per 100k)
gsdcountryper= pd.DataFrame(sd.groupby(['country','sex'])['suicides/100k pop'].sum().unstack())
gsdcountryper['Suicide number']=gsdcountryper.apply(lambda gsdcountryper: gsdcountryper['female']
                                                    +gsdcountryper['male'], axis = 1)
gsdcountryper = gsdcountryper.sort_values(by='Suicide number',ascending=False)
gsdcountryper.head(10)

gsdcountryper.ix[0:10,2].plot(kind='barh')
plt.ylabel('Country')
plt.xlabel('Suicide population (per 100k)')
plt.title('Top 10 country of suicide from 1987-2016')

plt.show()
In [29]:
#Top ten suicide country by percentage
gsdcountry10 = pd.DataFrame(gsdcountry.ix[0:10,2])

top10country = ["Russian Federation","Unites States","Japan","France","Ukraine","Germany","Republic of Korea","Brazil","Poland","United Kingdom"]

plt.pie(gsdcountry10,
               labels = top10country,
               autopct = '%.1f%%',
               startangle =0,
               radius = 1.5,
               frame = 0,
               center = (4.5,4.5),
               explode=(0.2,0,0,0,0,0,0,0,0,0)
               )
plt.show()
In [31]:
#Life expectancy dataset
le = pd.read_csv('Life expectancy.csv', index_col = 0, encoding='latin')
le.head(10)
Out[31]:
Year Life expectancy Alcohol HIV/AIDS Population
Country
Afghanistan 2015 65.0 0.01 0.1 33736494.0
Afghanistan 2014 59.9 0.01 0.1 327582.0
Afghanistan 2013 59.9 0.01 0.1 31731688.0
Afghanistan 2012 59.5 0.01 0.1 3696958.0
Afghanistan 2011 59.2 0.01 0.1 2978599.0
Afghanistan 2010 58.8 0.01 0.1 2883167.0
Afghanistan 2009 58.6 0.01 0.1 284331.0
Afghanistan 2008 58.1 0.03 0.1 2729431.0
Afghanistan 2007 57.5 0.02 0.1 26616792.0
Afghanistan 2006 57.3 0.03 0.1 2589345.0
In [32]:
#Life expectancy data group by country
leten = pd.DataFrame(le.loc[["Russian Federation","Lithuania","Hungary","Kazakhstan","Republic of Korea",
                             "Austria","Ukraine","Japan","Finland","Belgium"],:])
leten
letengp = pd.DataFrame(leten.groupby(['Country','Year'])['Life expectancy'].sum().unstack())
letengp = letengp.reindex(["Russian Federation","Lithuania","Hungary","Kazakhstan","Republic of Korea",
                           "Austria","Ukraine","Japan","Finland","Belgium"])
In [33]:
#The life expectancy by year (Top 10 suicide number country)
Tletengp = letengp.T
Tletengp.ix[:,:].plot(kind='line',figsize=(10,6), marker='.')         
plt.legend(bbox_to_anchor=(1,1),title='Country')
plt.title('Life expectancy of 10 country')
plt.xlabel('year')
plt.ylabel('Age')

plt.show()           
In [36]:
#Calculate life expectancy mean
letengp['life mean'] = letengp.mean(axis=1)
letengp
Out[36]:
Year 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 life mean
Country
Russian Federation 65.0 65.1 64.8 64.6 64.9 65.0 66.4 67.3 67.5 68.2 68.4 69.4 69.6 70.0 73.0 75.0 67.76250
Lithuania 71.6 71.2 71.4 71.6 71.6 78.0 76.0 72.0 71.1 72.2 72.4 72.8 73.0 73.0 73.4 73.6 72.80625
Hungary 71.7 72.3 72.5 72.5 72.9 72.9 73.4 73.5 74.1 74.2 74.5 74.8 75.0 75.5 75.6 75.8 73.82500
Kazakhstan 63.9 64.4 64.7 64.4 64.7 64.6 65.0 65.3 66.6 67.8 67.8 68.5 69.1 69.5 69.9 72.0 66.76250
Republic of Korea 76.0 76.7 77.1 77.6 78.2 78.7 79.4 79.8 83.0 86.0 87.0 81.1 81.2 81.7 82.0 82.3 80.48750
Austria 78.1 78.6 78.7 78.8 79.3 79.4 79.8 81.0 84.0 82.0 84.0 88.0 88.0 81.1 81.4 81.5 81.48125
Ukraine 67.5 67.7 67.6 67.6 67.4 67.0 67.7 67.5 67.7 69.2 69.8 75.0 77.0 71.0 78.0 71.3 69.93750
Japan 81.1 81.5 81.8 81.9 82.1 82.0 82.4 82.6 82.7 83.0 83.0 82.5 83.3 83.5 83.5 83.7 82.53750
Finland 77.5 78.0 78.1 78.4 78.7 78.9 79.2 79.3 79.6 79.7 79.9 83.0 84.0 87.0 89.0 81.1 80.71250
Belgium 77.6 78.0 78.0 78.3 78.8 78.9 79.4 79.5 79.5 79.8 80.0 83.0 83.0 87.0 89.0 81.1 80.68125
In [34]:
#GDP of top 10 suicide number countries
GDPfile = pd.read_csv('GDP.csv', index_col = 0)
GDPfile.head()
GDPfile['GDP mean'] = GDPfile.mean(axis=1)
GDP = GDPfile.reset_index()
GDP = pd.DataFrame(GDP.ix[:,["Country Name","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","GDP mean"]])

GDPdata = pd.DataFrame(GDPfile.loc[["Russian Federation","Lithuania","Hungary","Kazakhstan","Republic of Korea","Austria","Ukraine","Japan","Finland","Belgium"],
                                   ["2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015"]])

GDPdata['GDP mean'] = GDPdata.mean(axis=1)
GDPdata
Out[34]:
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 GDP mean
Country Name
Russian Federation 2.597080e+11 3.066030e+11 3.454700e+11 4.303480e+11 5.910170e+11 7.640170e+11 9.899310e+11 1.299710e+12 1.660850e+12 1.222640e+12 1.524920e+12 2.051660e+12 2.210260e+12 2.297130e+12 2.063660e+12 1.368400e+12 1.211645e+12
Lithuania 1.153921e+10 1.225250e+10 1.427836e+10 1.880258e+10 2.264993e+10 2.612558e+10 3.021606e+10 3.973818e+10 4.785055e+10 3.744067e+10 3.712052e+10 4.347687e+10 4.284820e+10 4.641734e+10 4.851637e+10 4.150861e+10 3.254885e+10
Hungary 4.731062e+10 5.382132e+10 6.771689e+10 8.532477e+10 1.040670e+11 1.130350e+11 1.152950e+11 1.398510e+11 1.579980e+11 1.305940e+11 1.309230e+11 1.407820e+11 1.278570e+11 1.352160e+11 1.401180e+11 1.228790e+11 1.132993e+11
Kazakhstan 1.829199e+10 2.215269e+10 2.463659e+10 3.083370e+10 4.315165e+10 5.712367e+10 8.100388e+10 1.048500e+11 1.334420e+11 1.153090e+11 1.480470e+11 1.926270e+11 2.079990e+11 2.366350e+11 2.214160e+11 1.843880e+11 1.138692e+11
Republic of Korea NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Austria 1.968000e+11 1.973380e+11 2.133780e+11 2.616960e+11 3.009040e+11 3.159740e+11 3.359990e+11 3.886910e+11 4.302940e+11 4.001720e+11 3.918930e+11 4.311200e+11 4.094250e+11 4.300690e+11 4.418850e+11 3.820660e+11 3.454815e+11
Ukraine 3.126153e+10 3.797230e+10 4.235159e+10 5.008420e+10 6.481970e+10 8.605792e+10 1.076480e+11 1.425800e+11 1.798170e+11 1.171130e+11 1.360130e+11 1.631600e+11 1.757810e+11 1.833100e+11 1.335030e+11 9.103096e+10 1.089064e+11
Japan 4.887520e+12 4.303540e+12 4.115120e+12 4.445660e+12 4.815150e+12 4.755410e+12 4.530380e+12 4.515260e+12 5.037910e+12 5.231380e+12 5.700100e+12 6.157460e+12 6.203210e+12 5.155720e+12 4.850410e+12 4.394980e+12 4.943701e+12
Finland 1.255400e+11 1.292500e+11 1.395530e+11 1.710710e+11 1.967680e+11 2.044360e+11 2.165530e+11 2.553850e+11 2.837420e+11 2.514990e+11 2.478000e+11 2.736740e+11 2.567060e+11 2.699800e+11 2.726090e+11 2.324650e+11 2.204394e+11
Belgium 2.379050e+11 2.378420e+11 2.588600e+11 3.190030e+11 3.708850e+11 3.873660e+11 4.098130e+11 4.718210e+11 5.186260e+11 4.845530e+11 4.835480e+11 5.270080e+11 4.978840e+11 5.209250e+11 5.307710e+11 4.550400e+11 4.194906e+11
In [35]:
#Draw a choropleth map of world to show the GDP by country
plotly.offline.init_notebook_mode()

colorscale = [[0,"#f7fbff"], 
              [0.1,"#ebf3fb"], 
              [0.2,"#deebf7"], 
              [0.3,"#d2e3f3"], 
              [0.4,"#c6dbef"], 
              [0.45,"#b3d2e9"], 
              [0.5,"#9ecae1"],
              [0.55,"#85bcdb"],
              [0.6,"#6baed6"], 
              [0.65,"#57a0ce"], 
              [0.7,"#4292c6"],
              [0.75,"#3082be"],
              [0.8,"#2171b5"],
              [0.85,"#1361a9"],
              [0.9,"#08519c"],
              [0.95,"#0b4083"],
              [1.0,"#08306b"]]


#data to graph
my_data01 = [dict(type='choropleth', 
        colorscale=colorscale,
        locations=GDP['Country Name'],
        z=GDP['GDP mean'].astype(float),
        locationmode='country names',
        text=GDP['Country Name'],
        hoverinfo='location+z',
        marker=dict(line=dict(color='rgb(180,180,180)',width=0.5)),
        colorbar=dict(title='GDP'))]

#layout
my_layout01 = dict(title='GDP',
                 geo=dict(scope='world',
                          projection=dict(type='mercator'),
                          showcoastlines= False,
                          showframe= False))

fig = dict(data=my_data01, layout=my_layout01)
py.iplot(fig, validata=False, filename='GDP')
Out[35]:
In [37]:
#Population dataset
popfile = pd.read_csv('population.csv', index_col = 0)
popfile.head()

popdata = pd.DataFrame(popfile.loc[:,["2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015"]])
popdata
Out[37]:
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
Country Name
Aruba 9.085300e+04 9.289800e+04 9.499200e+04 9.701700e+04 9.873700e+04 1.000310e+05 1.008320e+05 1.012200e+05 1.013530e+05 1.014530e+05 1.016690e+05 1.020530e+05 1.025770e+05 1.031870e+05 1.037950e+05 1.043410e+05
Afghanistan 2.009376e+07 2.096646e+07 2.197992e+07 2.306485e+07 2.411898e+07 2.507080e+07 2.589345e+07 2.661679e+07 2.729403e+07 2.800433e+07 2.880317e+07 2.970860e+07 3.069696e+07 3.173169e+07 3.275802e+07 3.373649e+07
Angola 1.644092e+07 1.698327e+07 1.757265e+07 1.820337e+07 1.886572e+07 1.955254e+07 2.026240e+07 2.099769e+07 2.175942e+07 2.254955e+07 2.336913e+07 2.421856e+07 2.509615e+07 2.599834e+07 2.692047e+07 2.785930e+07
Albania 3.089027e+06 3.060173e+06 3.051010e+06 3.039616e+06 3.026939e+06 3.011487e+06 2.992547e+06 2.970017e+06 2.947314e+06 2.927519e+06 2.913021e+06 2.905195e+06 2.900401e+06 2.895092e+06 2.889104e+06 2.880703e+06
Andorra 6.539000e+04 6.734100e+04 7.004900e+04 7.318200e+04 7.624400e+04 7.886700e+04 8.099100e+04 8.268300e+04 8.386100e+04 8.446200e+04 8.444900e+04 8.375100e+04 8.243100e+04 8.078800e+04 7.922300e+04 7.801400e+04
Arab World 2.838320e+08 2.898504e+08 2.960266e+08 3.024345e+08 3.091620e+08 3.162647e+08 3.237733e+08 3.316538e+08 3.398255e+08 3.481451e+08 3.565089e+08 3.648959e+08 3.733070e+08 3.817021e+08 3.900430e+08 3.983050e+08
United Arab Emirates 3.154925e+06 3.326032e+06 3.507232e+06 3.741932e+06 4.087931e+06 4.579562e+06 5.242032e+06 6.044067e+06 6.894278e+06 7.666393e+06 8.270684e+06 8.672475e+06 8.900453e+06 9.006263e+06 9.070867e+06 9.154302e+06
Argentina 3.705745e+07 3.747151e+07 3.788937e+07 3.830938e+07 3.872870e+07 3.914549e+07 3.955889e+07 3.997022e+07 4.038239e+07 4.079941e+07 4.122389e+07 4.165688e+07 4.209674e+07 4.253992e+07 4.298152e+07 4.341776e+07
Armenia 3.069588e+06 3.050655e+06 3.033897e+06 3.017806e+06 3.000612e+06 2.981259e+06 2.958500e+06 2.933056e+06 2.908220e+06 2.888584e+06 2.877311e+06 2.875581e+06 2.881922e+06 2.893509e+06 2.906220e+06 2.916950e+06
American Samoa 5.752100e+04 5.817500e+04 5.873100e+04 5.911700e+04 5.926400e+04 5.911800e+04 5.865000e+04 5.790300e+04 5.703000e+04 5.622700e+04 5.563700e+04 5.532000e+04 5.523000e+04 5.530700e+04 5.543700e+04 5.553700e+04
Antigua and Barbuda 8.358400e+04 8.505700e+04 8.626600e+04 8.729300e+04 8.825700e+04 8.925300e+04 9.030100e+04 9.138100e+04 9.247800e+04 9.358100e+04 9.466100e+04 9.571900e+04 9.677700e+04 9.782400e+04 9.887500e+04 9.992300e+04
Australia 1.915300e+07 1.941300e+07 1.965140e+07 1.989540e+07 2.012740e+07 2.039480e+07 2.069790e+07 2.082760e+07 2.124920e+07 2.169170e+07 2.203175e+07 2.234002e+07 2.274248e+07 2.314590e+07 2.350414e+07 2.385078e+07
Austria 8.011566e+06 8.042293e+06 8.081957e+06 8.121423e+06 8.171966e+06 8.227829e+06 8.268641e+06 8.295487e+06 8.321496e+06 8.343323e+06 8.363404e+06 8.391643e+06 8.429991e+06 8.479823e+06 8.546356e+06 8.642699e+06
Azerbaijan 8.048600e+06 8.111200e+06 8.171950e+06 8.234100e+06 8.306500e+06 8.391850e+06 8.484550e+06 8.581300e+06 8.763400e+06 8.947243e+06 9.054332e+06 9.173082e+06 9.295784e+06 9.416801e+06 9.535079e+06 9.649341e+06
Burundi 6.400706e+06 6.555829e+06 6.741569e+06 6.953113e+06 7.182451e+06 7.423289e+06 7.675338e+06 7.939573e+06 8.212264e+06 8.489031e+06 8.766930e+06 9.043508e+06 9.319710e+06 9.600186e+06 9.891790e+06 1.019927e+07
Belgium 1.025125e+07 1.028657e+07 1.033278e+07 1.037613e+07 1.042114e+07 1.047862e+07 1.054796e+07 1.062570e+07 1.070997e+07 1.079649e+07 1.089559e+07 1.104774e+07 1.112825e+07 1.118282e+07 1.120906e+07 1.127420e+07
Benin 6.865951e+06 7.076733e+06 7.295394e+06 7.520555e+06 7.750004e+06 7.982225e+06 8.216896e+06 8.454791e+06 8.696916e+06 8.944706e+06 9.199259e+06 9.460802e+06 9.729160e+06 1.000445e+07 1.028671e+07 1.057595e+07
Burkina Faso 1.160794e+07 1.194459e+07 1.229310e+07 1.265462e+07 1.303057e+07 1.342193e+07 1.382918e+07 1.425202e+07 1.468973e+07 1.514110e+07 1.560522e+07 1.608190e+07 1.657122e+07 1.707272e+07 1.758598e+07 1.811062e+07
Bangladesh 1.315812e+08 1.341072e+08 1.366007e+08 1.390190e+08 1.413075e+08 1.434311e+08 1.453680e+08 1.471392e+08 1.488058e+08 1.504547e+08 1.521491e+08 1.539119e+08 1.557271e+08 1.575713e+08 1.594053e+08 1.612009e+08
Bulgaria 8.170172e+06 8.009142e+06 7.837161e+06 7.775327e+06 7.716860e+06 7.658972e+06 7.601022e+06 7.545338e+06 7.492561e+06 7.444443e+06 7.395599e+06 7.348328e+06 7.305888e+06 7.265115e+06 7.223938e+06 7.177991e+06
Bahrain 6.646140e+05 6.975490e+05 7.351480e+05 7.787110e+05 8.298480e+05 8.891680e+05 9.584140e+05 1.035891e+06 1.114590e+06 1.185029e+06 1.240862e+06 1.278269e+06 1.300217e+06 1.315411e+06 1.336397e+06 1.371855e+06
Bahamas, The 2.978900e+05 3.031350e+05 3.091570e+05 3.157460e+05 3.225260e+05 3.292490e+05 3.358300e+05 3.423280e+05 3.486760e+05 3.548560e+05 3.608320e+05 3.665680e+05 3.720390e+05 3.772400e+05 3.821690e+05 3.868380e+05
Bosnia and Herzegovina 3.766706e+06 3.771284e+06 3.775807e+06 3.779247e+06 3.781287e+06 3.781530e+06 3.779468e+06 3.774000e+06 3.763599e+06 3.746561e+06 3.722084e+06 3.688865e+06 3.648200e+06 3.604999e+06 3.566002e+06 3.535961e+06
Belarus 9.979610e+06 9.928549e+06 9.865548e+06 9.796749e+06 9.730146e+06 9.663915e+06 9.604924e+06 9.560953e+06 9.527985e+06 9.506765e+06 9.490583e+06 9.473172e+06 9.464495e+06 9.465997e+06 9.474511e+06 9.489616e+06
Belize 2.473150e+05 2.549840e+05 2.622060e+05 2.691300e+05 2.760890e+05 2.832770e+05 2.907470e+05 2.984070e+05 3.061650e+05 3.139290e+05 3.216080e+05 3.291920e+05 3.367010e+05 3.441810e+05 3.516940e+05 3.592880e+05
Bermuda 6.183300e+04 6.250400e+04 6.291200e+04 6.332500e+04 6.374000e+04 6.415400e+04 6.452300e+04 6.488800e+04 6.527300e+04 6.563600e+04 6.512400e+04 6.456400e+04 6.479800e+04 6.500100e+04 6.513900e+04 6.523900e+04
Bolivia 8.339512e+06 8.496375e+06 8.653345e+06 8.810420e+06 8.967741e+06 9.125409e+06 9.283334e+06 9.441444e+06 9.599855e+06 9.758748e+06 9.918242e+06 1.007834e+07 1.023900e+07 1.040026e+07 1.056216e+07 1.072470e+07
Brazil 1.752876e+08 1.777507e+08 1.801510e+08 1.824821e+08 1.847385e+08 1.869174e+08 1.890124e+08 1.910266e+08 1.929790e+08 1.948960e+08 1.967963e+08 1.986867e+08 2.005610e+08 2.024086e+08 2.042131e+08 2.059621e+08
Barbados 2.698470e+05 2.706850e+05 2.714780e+05 2.722580e+05 2.730910e+05 2.740090e+05 2.750390e+05 2.761500e+05 2.773190e+05 2.784700e+05 2.795690e+05 2.806010e+05 2.815850e+05 2.825090e+05 2.833850e+05 2.842170e+05
Brunei Darussalam 3.332410e+05 3.401170e+05 3.468670e+05 3.533890e+05 3.595230e+05 3.651580e+05 3.702500e+05 3.748640e+05 3.792520e+05 3.837720e+05 3.886620e+05 3.940130e+05 3.997480e+05 4.057160e+05 4.117040e+05 4.175420e+05
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Latin America & the Caribbean (IDA & IBRD countries) 5.088267e+08 5.161201e+08 5.232708e+08 5.303320e+08 5.373774e+08 5.444598e+08 5.515955e+08 5.587681e+08 5.659562e+08 5.731253e+08 5.802468e+08 5.873151e+08 5.943307e+08 6.012772e+08 6.081360e+08 6.148920e+08
Timor-Leste 8.716070e+05 8.925310e+05 9.238250e+05 9.608520e+05 9.966980e+05 1.026484e+06 1.048621e+06 1.064973e+06 1.078110e+06 1.092021e+06 1.109591e+06 1.131523e+06 1.156760e+06 1.184366e+06 1.212814e+06 1.240977e+06
Middle East & North Africa (IDA & IBRD countries) 2.780331e+08 2.830183e+08 2.879756e+08 2.929596e+08 2.980417e+08 3.032748e+08 3.086730e+08 3.142267e+08 3.199345e+08 3.257867e+08 3.317705e+08 3.378950e+08 3.441488e+08 3.504715e+08 3.567833e+08 3.630272e+08
Tonga 9.808200e+04 9.861100e+04 9.918400e+04 9.978900e+04 1.004060e+05 1.010410e+05 1.016890e+05 1.023570e+05 1.030050e+05 1.036040e+05 1.041370e+05 1.045770e+05 1.049510e+05 1.053280e+05 1.057820e+05 1.063640e+05
South Asia (IDA & IBRD) 1.386626e+09 1.412104e+09 1.437568e+09 1.462907e+09 1.487975e+09 1.512671e+09 1.536944e+09 1.560819e+09 1.584359e+09 1.607664e+09 1.630807e+09 1.653799e+09 1.676615e+09 1.699310e+09 1.721848e+09 1.744200e+09
Sub-Saharan Africa (IDA & IBRD countries) 6.706496e+08 6.886160e+08 7.070998e+08 7.261406e+08 7.457881e+08 7.660805e+08 7.870358e+08 8.086602e+08 8.309656e+08 8.539537e+08 8.776284e+08 9.019899e+08 9.270399e+08 9.527341e+08 9.790179e+08 1.005850e+09
Trinidad and Tobago 1.267984e+06 1.272380e+06 1.277837e+06 1.284052e+06 1.290535e+06 1.296934e+06 1.303144e+06 1.309260e+06 1.315372e+06 1.321618e+06 1.328100e+06 1.334788e+06 1.341588e+06 1.348248e+06 1.354493e+06 1.360092e+06
Tunisia 9.699197e+06 9.785701e+06 9.864326e+06 9.939678e+06 1.001760e+07 1.010248e+07 1.019614e+07 1.029809e+07 1.040734e+07 1.052183e+07 1.063993e+07 1.076147e+07 1.088667e+07 1.101456e+07 1.114391e+07 1.127366e+07
Turkey 6.324012e+07 6.419147e+07 6.514305e+07 6.608580e+07 6.700786e+07 6.790341e+07 6.876340e+07 6.959728e+07 7.044003e+07 7.133918e+07 7.232691e+07 7.340946e+07 7.456987e+07 7.578733e+07 7.703063e+07 7.827147e+07
Tuvalu 9.420000e+03 9.512000e+03 9.635000e+03 9.767000e+03 9.894000e+03 1.002700e+04 1.013700e+04 1.024300e+04 1.034000e+04 1.044100e+04 1.053100e+04 1.062800e+04 1.072500e+04 1.081900e+04 1.090800e+04 1.100100e+04
Tanzania 3.417804e+07 3.511702e+07 3.610581e+07 3.714907e+07 3.824998e+07 3.941054e+07 4.063495e+07 4.192372e+07 4.327014e+07 4.466423e+07 4.609859e+07 4.757090e+07 4.908300e+07 5.063660e+07 5.223487e+07 5.387996e+07
Uganda 2.403927e+07 2.485489e+07 2.571805e+07 2.662482e+07 2.756844e+07 2.854394e+07 2.955066e+07 3.059049e+07 3.166390e+07 3.277190e+07 3.391513e+07 3.509365e+07 3.630680e+07 3.755373e+07 3.883334e+07 4.014487e+07
Ukraine 4.917585e+07 4.868386e+07 4.820250e+07 4.781295e+07 4.745160e+07 4.710515e+07 4.678775e+07 4.650935e+07 4.625820e+07 4.605330e+07 4.587070e+07 4.570610e+07 4.559330e+07 4.548960e+07 4.527195e+07 4.515403e+07
Upper middle income 2.260806e+09 2.280191e+09 2.298542e+09 2.316548e+09 2.334314e+09 2.352105e+09 2.369651e+09 2.386825e+09 2.404283e+09 2.422394e+09 2.440543e+09 2.459176e+09 2.478492e+09 2.498184e+09 2.517980e+09 2.537437e+09
Uruguay 3.321245e+06 3.327103e+06 3.327773e+06 3.325637e+06 3.324096e+06 3.325612e+06 3.331043e+06 3.339741e+06 3.350824e+06 3.362755e+06 3.374415e+06 3.385624e+06 3.396777e+06 3.408005e+06 3.419546e+06 3.431552e+06
United States 2.821624e+08 2.849690e+08 2.876252e+08 2.901079e+08 2.928053e+08 2.955166e+08 2.983799e+08 3.012312e+08 3.040940e+08 3.067715e+08 3.093384e+08 3.116443e+08 3.139933e+08 3.162345e+08 3.186225e+08 3.210398e+08
Uzbekistan 2.465040e+07 2.496445e+07 2.527185e+07 2.556765e+07 2.586435e+07 2.616700e+07 2.648825e+07 2.686800e+07 2.730280e+07 2.776740e+07 2.856240e+07 2.933940e+07 2.977450e+07 3.024320e+07 3.075770e+07 3.129890e+07
St. Vincent and the Grenadines 1.078980e+05 1.079880e+05 1.081460e+05 1.083500e+05 1.085590e+05 1.087440e+05 1.089070e+05 1.090470e+05 1.091650e+05 1.092530e+05 1.093150e+05 1.093410e+05 1.093280e+05 1.093200e+05 1.093570e+05 1.094550e+05
Venezuela, RB 2.448834e+07 2.494848e+07 2.540870e+07 2.586852e+07 2.632722e+07 2.678416e+07 2.723917e+07 2.769196e+07 2.814170e+07 2.858732e+07 2.902803e+07 2.946329e+07 2.989308e+07 3.031785e+07 3.073838e+07 3.115513e+07
British Virgin Islands 2.064500e+04 2.108500e+04 2.152900e+04 2.200000e+04 2.254100e+04 2.316800e+04 2.390500e+04 2.473100e+04 2.560400e+04 2.644700e+04 2.722400e+04 2.790100e+04 2.850900e+04 2.905600e+04 2.958800e+04 3.011300e+04
Virgin Islands (U.S.) 1.086420e+05 1.085490e+05 1.085100e+05 1.085060e+05 1.084670e+05 1.084540e+05 1.083710e+05 1.083390e+05 1.083990e+05 1.084050e+05 1.083580e+05 1.082920e+05 1.081910e+05 1.080440e+05 1.078840e+05 1.077100e+05
Vietnam 8.028556e+07 8.113992e+07 8.195650e+07 8.274766e+07 8.352768e+07 8.430884e+07 8.509462e+07 8.588959e+07 8.670780e+07 8.756541e+07 8.847251e+07 8.943664e+07 9.045188e+07 9.149772e+07 9.254492e+07 9.357157e+07
Vanuatu 1.850630e+05 1.892900e+05 1.939560e+05 1.989640e+05 2.041430e+05 2.093700e+05 2.146340e+05 2.199530e+05 2.253400e+05 2.307850e+05 2.362950e+05 2.418710e+05 2.474850e+05 2.531420e+05 2.588500e+05 2.646030e+05
World 6.121683e+09 6.201340e+09 6.280530e+09 6.359899e+09 6.439825e+09 6.520299e+09 6.601477e+09 6.683224e+09 6.766297e+09 6.849569e+09 6.932870e+09 7.014984e+09 7.099558e+09 7.185138e+09 7.271323e+09 7.357559e+09
Samoa 1.746100e+05 1.755660e+05 1.765820e+05 1.776620e+05 1.787810e+05 1.799290e+05 1.810940e+05 1.822860e+05 1.835260e+05 1.848260e+05 1.862050e+05 1.876650e+05 1.891940e+05 1.907570e+05 1.922900e+05 1.937590e+05
Kosovo 1.700000e+06 1.701154e+06 1.702310e+06 1.703466e+06 1.704622e+06 1.705780e+06 1.719536e+06 1.733404e+06 1.747383e+06 1.761474e+06 1.775680e+06 1.791000e+06 1.805200e+06 1.824100e+06 1.821800e+06 1.801800e+06
Yemen, Rep. 1.787472e+07 1.839014e+07 1.891918e+07 1.946209e+07 2.001707e+07 2.058293e+07 2.116053e+07 2.175160e+07 2.235639e+07 2.297493e+07 2.360678e+07 2.425221e+07 2.490997e+07 2.557632e+07 2.624633e+07 2.691621e+07
South Africa 4.572832e+07 4.638501e+07 4.702617e+07 4.764873e+07 4.824740e+07 4.882059e+07 4.936458e+07 4.988718e+07 5.041213e+07 5.097082e+07 5.158466e+07 5.226352e+07 5.299821e+07 5.376740e+07 5.453957e+07 5.529122e+07
Zambia 1.053122e+07 1.082412e+07 1.112041e+07 1.142198e+07 1.173175e+07 1.205216e+07 1.238345e+07 1.272597e+07 1.308252e+07 1.345642e+07 1.385003e+07 1.426476e+07 1.469994e+07 1.515321e+07 1.562097e+07 1.610059e+07
Zimbabwe 1.222225e+07 1.236616e+07 1.250052e+07 1.263390e+07 1.277751e+07 1.294003e+07 1.312427e+07 1.332991e+07 1.355847e+07 1.381060e+07 1.408632e+07 1.438665e+07 1.471083e+07 1.505451e+07 1.541168e+07 1.577745e+07

264 rows × 16 columns

In [47]:
#GDP of per capita
GDPdata02 = pd.DataFrame(GDPfile.loc[:,["2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015"]])
GDPdata02['GDP mean'] = GDPdata02.mean(axis=1)
perGDP = GDPdata02/popdata
perGDP['perGDP mean'] = perGDP.mean(axis=1)

perGDP = pd.DataFrame(perGDP.ix[:,["2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","perGDP mean"]])
perGDP.dropna()
perGDP
Out[47]:
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 perGDP mean
Country Name
Aruba 20620.700626 20669.031971 20436.887127 20833.761609 22569.974984 23300.039558 24045.749425 25835.643144 27086.039851 24630.939272 23512.602593 24984.279443 24709.602270 25018.308954 25528.403777 25796.380253 23723.646553
Afghanistan NaN NaN 184.494712 195.776630 216.708129 247.664140 269.229693 366.230443 370.382294 444.184404 550.514974 599.297630 648.511070 647.966460 625.339539 590.076474 425.455471
Angola 555.296942 526.168743 869.851485 978.538934 1248.404906 1890.849727 2585.133522 3108.268643 4068.978456 3117.896944 3585.905553 4615.880421 5102.495801 5258.412653 5412.684907 4170.742953 2943.469412
Albania 1126.683340 1281.659826 1425.124219 1846.120121 2373.581292 2673.786584 2972.742924 3595.038057 4370.539925 4114.134899 4094.360204 4437.177795 4247.614342 4413.082887 4578.667934 3952.830781 3218.946571
Andorra 21936.530096 22228.846498 24741.493569 32776.442267 38503.479618 41282.020122 43748.772160 48582.808449 47785.659091 43339.379875 39736.354060 41098.766940 38391.080868 40619.711294 42294.994724 36038.267606 37694.037952
Arab World 2590.222239 2495.939655 2463.397078 2722.377732 3119.163770 3747.303746 4338.375512 4939.518301 6116.580727 5159.343133 5918.309340 6856.037985 7465.142771 7510.726572 7456.587584 6429.119035 4958.009074
United Arab Emirates 33071.150661 31061.637411 31311.301904 33230.427490 36161.080018 39439.797954 42372.309059 42672.591154 45758.961272 33072.528372 35037.851767 40434.362740 42086.734237 43315.190773 44443.050482 39122.043385 38286.938667
Argentina 7669.280662 7170.701345 2579.193168 3330.437698 4251.576144 5076.881402 5878.754434 7193.629938 8953.358356 8161.295089 10276.250259 12726.901600 12969.698199 12976.633128 12245.264040 13698.286865 8447.383895
Armenia 622.742748 694.430512 783.261610 930.166157 1191.961920 1643.758543 2158.002909 3138.808703 4010.026997 2993.832531 3218.381655 3526.978143 3684.804810 3843.591213 3994.712355 3617.935746 2503.337284
American Samoa NaN NaN 8751.766529 8914.525433 8639.308855 8508.406915 8456.947997 8980.536414 9871.997194 12058.263823 10352.822762 10375.994215 11660.329531 11589.853002 11598.751736 11901.975260 10118.677119
Antigua and Barbuda 9932.029682 9414.160591 9443.063591 9801.966934 10419.311132 11452.738776 12812.764432 14350.918889 14797.368488 13082.281809 12174.697806 11931.204003 12517.557932 12194.549589 12900.902999 13602.421234 11926.746118
Australia 21669.399050 19482.563231 20074.244074 23437.327221 30401.542176 33961.696119 36019.209678 40905.481188 49535.041319 42709.792225 51936.863844 62411.750319 67864.645339 67990.440294 62327.748416 56561.243438 42955.561746
Austria 24564.485895 24537.529284 26401.773729 32222.924480 36821.494363 38403.083000 40635.335359 46855.718055 51708.731219 47963.143702 46858.073579 51374.921455 48567.667510 50716.742555 51704.492535 44206.792346 41471.431816
Azerbaijan 655.097433 703.683843 763.080638 883.643997 1045.009379 1578.402390 2473.081819 3851.437869 5574.603802 4950.294791 5842.805784 7189.691229 7496.294648 7875.756952 7891.313147 5500.310382 4017.156756
Burundi 135.998445 133.742769 122.433589 112.849370 127.429665 150.487614 165.904748 170.815152 196.271808 209.853762 231.795537 247.229379 250.362737 255.372691 273.538285 304.374221 193.028736
Belgium 23207.413730 23121.604189 25052.297130 30743.919724 35589.686615 36967.282992 38852.354171 44403.756929 48424.585197 44880.592244 44380.173769 47702.770810 44740.563787 46582.627615 47351.976174 40361.192940 38897.674876
Benin 374.192394 378.736054 418.698576 519.292285 583.409351 601.799977 625.830092 706.053542 820.151350 793.452430 757.695907 825.942785 837.950500 915.328155 943.686575 783.963078 680.386441
Burkina Faso 226.475981 235.491232 260.763541 332.344305 371.323087 406.998807 420.582523 475.110012 569.761278 552.745552 575.446453 666.840410 673.822818 699.781537 703.821656 575.314454 484.163978
Bangladesh 405.603307 402.598115 400.613575 432.738897 460.757917 484.155407 494.050147 541.065148 615.777541 681.121923 757.671248 835.789738 856.344466 951.886591 1084.562576 1210.160842 663.431090
Bulgaria 1609.882452 1757.443780 2076.830682 2698.624248 3363.799644 3869.529455 4490.201777 5885.949252 7261.754492 6969.558557 6843.266950 7813.806692 7378.024730 7646.839866 7864.760672 6993.783483 5282.753546
Bahrain 13636.346684 12868.210997 13102.334568 14221.992593 15846.476409 17959.178538 19307.995492 20977.110526 23067.565347 19356.672356 20722.103890 22512.159604 23649.366614 24737.171783 24983.379015 22688.878244 19352.308916
Bahamas, The 27112.256202 27439.358702 28727.022193 28092.485732 28076.155101 29874.654137 30274.990322 31018.029492 30188.484438 28129.607503 27979.114934 27472.256171 28815.527404 28171.986004 28671.346970 30483.820100 28782.943463
Bosnia and Herzegovina 1461.750520 1524.412021 1761.537647 2214.732246 2802.274917 2967.834056 3403.815297 4180.913532 5078.314577 4701.334426 4614.829041 5054.325344 4722.013403 5042.582213 5204.243718 4584.242548 3707.447219
Belarus 1276.288034 1244.373185 1479.314583 1819.766059 2378.623286 3125.810535 3847.434124 4735.657608 6377.369732 5351.355382 6181.399916 6519.230195 6940.159254 7978.872615 8318.512690 5949.106307 4595.204594
Belize 3364.423711 3419.275719 3556.561825 3679.909523 3831.538019 3933.262143 4187.290497 4324.773045 4470.220796 4253.246753 4342.963173 4515.892701 4644.559565 4673.245037 4813.718033 4905.536645 4182.276074
Bermuda 56284.168648 58883.959427 62583.100203 66111.725227 70359.319109 75882.033856 83912.697798 90849.586981 93605.748165 88463.312816 88207.327560 85973.158416 85458.455508 85748.065414 NaN NaN 78023.047081
Bolivia 1007.002869 958.236652 913.575642 917.364310 978.334648 1046.427384 1233.591869 1389.629350 1736.930084 1776.866476 1981.170116 2377.688771 2645.227753 2947.938526 3124.000310 3077.026199 1756.938185
Brazil 3739.118161 3146.947350 2819.645413 3059.586941 3623.051785 4770.182905 5860.144253 7313.535023 8787.586966 8553.382492 11224.145718 13167.464949 12291.473462 12216.919682 12026.601639 8750.201760 7584.374281
Barbados 11567.666122 11513.936864 11675.347542 12028.480339 12868.787327 14223.255441 15185.119201 16919.246786 17243.679661 16087.729378 16203.155572 16610.418352 16536.214642 16326.913479 16261.799319 16129.049283 14836.299957
Brunei Darussalam 18008.448258 16468.128862 16846.021985 18555.566486 21896.605266 26102.133455 30980.966920 32672.367170 37951.280597 27965.475037 35268.101170 47017.027301 47651.259091 44597.279681 41530.668978 30967.890507 30904.951298
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Latin America & the Caribbean (IDA & IBRD countries) 4273.262306 4100.150246 3596.742105 3619.713791 4136.906483 4971.019063 5769.843764 6745.357016 7778.728782 7195.564780 8880.204140 10008.323828 9985.938082 10114.336515 10194.199194 8602.551776 6873.302617
Timor-Leste 504.355747 580.035876 552.810327 565.539750 1081.972674 1767.002700 2534.662190 2705.232903 4073.239280 2929.980284 3603.940551 5021.462224 5766.969812 4770.315933 3335.548567 2501.577386 2643.415388
Middle East & North Africa (IDA & IBRD countries) 1608.840604 1637.130648 1563.066302 1733.406440 1975.623080 2287.786387 2613.613988 3175.051996 3840.692860 3648.614072 4143.286357 4611.077515 4989.644072 4597.035209 4444.097953 3942.900548 3175.741752
Tonga 2063.207237 1837.977391 1842.404421 2029.714718 2284.307858 2594.749990 2892.522663 2932.315884 3392.887992 3070.987248 3548.068398 4044.979721 4500.750362 4278.884567 4196.470593 4093.849585 3100.254914
South Asia (IDA & IBRD) 444.333994 447.726112 461.318627 529.356393 603.415956 679.969603 765.265590 953.730146 956.576100 1036.000125 1252.177769 1373.734372 1370.188939 1387.133234 1499.476331 1545.763150 956.635402
Sub-Saharan Africa (IDA & IBRD countries) 584.639099 542.806154 576.755885 704.519191 855.882501 992.368286 1151.175092 1300.138234 1450.252650 1342.215694 1556.752324 1719.498140 1761.930683 1826.154906 1866.053692 1655.385911 1242.908028
Trinidad and Tobago 6430.947262 6935.721450 7049.626612 8804.518666 10290.519144 12323.127053 14096.186679 16529.658013 21189.129273 14506.586038 16683.422424 19004.157145 19083.214813 19713.379288 20081.521909 17941.237942 14416.434607
Tunisia 2213.914088 2254.933125 2346.059369 2761.969249 3112.835029 3194.562243 3371.712310 3778.184171 4310.093026 4129.977335 4140.151770 4256.912790 4137.548140 4199.084678 4274.292832 3827.729834 3519.372499
Turkey 4316.563531 3119.604326 3660.067887 4718.456701 6040.873865 7384.254039 8034.607943 9709.718401 10850.875252 9036.268076 10672.403360 11340.827963 11720.310565 12542.716076 12127.461819 10984.806827 8516.238539
Tuvalu 1458.817097 1387.357543 1603.631992 1866.599625 2176.564747 2178.029210 2259.333279 2638.911845 2929.421640 2595.639908 3021.889528 3642.437688 3512.516068 3466.967564 3418.645719 3232.073341 2586.802300
Tanzania 298.021355 295.684568 299.275947 313.847137 335.315214 429.579865 457.991489 512.877777 632.500469 639.746312 681.357022 712.156038 796.361273 877.105075 923.133153 846.851462 565.737760
Uganda 257.630361 234.984078 240.242323 237.999592 288.023695 315.788023 336.459392 401.850863 449.692818 554.404991 595.206173 574.919577 636.638204 655.049532 702.795104 675.121140 447.300367
Ukraine 635.708964 779.977131 878.618202 1047.502769 1366.017225 1826.932206 2300.773172 3065.620139 3887.245937 2542.988233 2965.138967 3569.764211 3855.412966 4029.712286 2948.912270 2016.009678 2357.270897
Upper middle income 1880.913282 1898.235388 1963.497283 2177.286715 2590.067244 3094.334465 3653.804204 4513.779167 5474.520993 5238.949972 6297.696671 7470.470740 7953.345219 8403.063279 8624.572886 7968.394701 4950.183263
Uruguay 6871.897678 6281.377047 4088.768855 3622.052284 4117.308853 5220.951116 5877.876078 7009.697050 9062.312171 9415.170382 11938.212002 14166.499087 15092.068192 16881.205676 16737.898272 15524.842468 9494.258576
United States 36449.929541 37273.533884 38165.989166 39677.301758 41921.714135 44307.832603 46437.107334 48061.421472 48401.486533 47001.428219 48375.497462 49793.630096 51451.102430 52782.032751 54696.697919 56443.773634 46327.529934
Uzbekistan 558.226802 456.706290 383.343068 396.377979 465.119887 546.776850 654.283837 830.407694 1082.286025 1213.265328 1377.082140 1564.966945 1740.468298 1907.551233 2050.448414 2137.576852 1085.305478
St. Vincent and the Grenadines 3672.555287 3982.287813 4270.924902 4446.758618 4808.215911 5064.451066 5609.648939 6276.617049 6370.437887 6177.610514 6231.770233 6183.676822 6338.117780 6597.228304 6654.484003 6901.996541 5599.173854
Venezuela, RB 4783.541882 4926.312934 3655.975620 3232.524276 4271.357881 5432.688371 6735.815132 8318.802945 11227.217573 11536.162375 13545.251240 10741.569908 12754.992125 12237.181214 15692.402507 NaN 8606.119732
British Virgin Islands NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Virgin Islands (U.S.) NaN NaN 30126.255645 31823.124988 35024.477491 40929.795121 41560.934198 44333.065655 39207.003755 38771.274388 40043.190166 39144.165774 37849.728721 34819.147755 33573.097030 34899.266549 37293.180517
Vietnam 388.270539 402.825134 427.838026 477.989497 543.865887 683.596804 779.974893 901.324893 1143.268575 1210.694995 1310.373102 1515.475022 1722.683910 1871.325216 2012.050041 2065.167937 1091.045279
Vanuatu 1469.849149 1362.601731 1353.934819 1580.502724 1787.947023 1886.433359 2047.097823 2393.367264 2697.961374 2643.441423 2965.802434 3275.091684 3158.586880 3167.343056 3148.365103 2788.770919 2357.943548
World 5488.343883 5386.093749 5522.814100 6120.615782 6808.383365 7282.979159 7793.105024 8671.458861 9395.819163 8798.669963 9514.948707 10451.456530 10563.151073 10730.316535 10890.521842 10182.194314 8350.054503
Samoa 1540.689023 1555.474051 1631.417027 1907.209417 2351.033815 2571.286691 2807.954274 3022.561554 3509.761499 3035.068269 3453.434298 3942.051645 4234.640751 4219.024861 4187.230599 4150.003780 3007.427597
Kosovo 1087.762401 1490.361033 1413.532587 1638.104739 2086.537326 2147.464271 2237.126598 2685.986222 3254.820270 3209.694108 3283.510304 3736.363217 3600.673475 3876.958302 4054.721339 3574.543333 2711.134970
Yemen, Rep. 540.004737 536.241854 565.279714 605.174937 693.048136 813.603661 900.826916 995.353321 1203.720733 1093.812918 1309.231960 1349.420250 1421.171575 1580.181601 1647.033657 1693.907815 1059.250861
South Africa 2982.003601 2621.558354 2461.352745 3678.104559 4745.064474 5277.916984 5502.690168 6001.862482 5688.511985 5805.988831 7276.368172 7967.680552 7478.138933 6819.058152 6429.020133 5742.990863 5404.894437
Zambia 341.905563 378.273624 377.130524 429.158343 530.277222 691.317816 1030.154199 1104.587985 1369.068249 1139.110233 1463.213573 1644.619672 1734.930612 1850.793359 1738.088202 1313.889646 1071.032426
Zimbabwe 547.358878 548.058731 507.348003 453.351155 454.360665 444.760508 414.796232 396.998217 325.678570 699.882264 854.847665 980.208824 1163.418689 1268.126633 1264.983826 1265.294413 724.342080

264 rows × 17 columns

In [48]:
#perGDP vs suicide
combine04 = pd.concat([perGDP,gsdcountryper],axis=1)
combine04 = combine04.ix[:,['perGDP mean','Suicide number']]
combine04
Out[48]:
perGDP mean Suicide number
Afghanistan 425.455471 NaN
Albania 3218.946571 924.76
Algeria 3737.029476 NaN
American Samoa 10118.677119 NaN
Andorra 37694.037952 NaN
Angola 2943.469412 NaN
Antigua and Barbuda 11926.746118 179.14
Arab World 4958.009074 NaN
Argentina 8447.383895 3894.59
Armenia 2503.337284 976.21
Aruba 23723.646553 1596.52
Australia 42955.561746 4677.41
Austria 41471.431816 9076.23
Azerbaijan 4017.156756 356.24
Bahamas NaN 344.28
Bahamas, The 28782.943463 NaN
Bahrain 19352.308916 467.24
Bangladesh 663.431090 NaN
Barbados 14836.299957 891.13
Belarus 4595.204594 7831.13
Belgium 38897.674876 7900.50
Belize 4182.276074 2093.49
Benin 680.386441 NaN
Bermuda 78023.047081 NaN
Bhutan 1687.023703 NaN
Bolivia 1756.938185 NaN
Bosnia and Herzegovina 3707.447219 110.81
Botswana 5474.333814 NaN
Brazil 7584.374281 2174.72
British Virgin Islands NaN NaN
... ... ...
Syrian Arab Republic 1469.880914 NaN
Tajikistan 579.346466 NaN
Tanzania 565.737760 NaN
Thailand 4014.749588 2362.67
Timor-Leste 2643.415388 NaN
Togo 469.207157 NaN
Tonga 3100.254914 NaN
Trinidad and Tobago 14416.434607 4479.51
Tunisia 3519.372499 NaN
Turkey 8516.238539 199.17
Turkmenistan 3623.092927 2994.73
Turks and Caicos Islands NaN NaN
Tuvalu 2586.802300 NaN
Uganda 447.300367 NaN
Ukraine 2357.270897 8931.66
United Arab Emirates 38286.938667 94.89
United Kingdom 39775.770878 2790.92
United States 46327.529934 5140.97
Upper middle income 4950.183263 NaN
Uruguay 9494.258576 6538.96
Uzbekistan 1085.305478 2138.17
Vanuatu 2357.943548 NaN
Venezuela, RB 8606.119732 NaN
Vietnam 1091.045279 NaN
Virgin Islands (U.S.) 37293.180517 NaN
West Bank and Gaza 1966.481465 NaN
World 8350.054503 NaN
Yemen, Rep. 1059.250861 NaN
Zambia 1071.032426 NaN
Zimbabwe 724.342080 NaN

272 rows × 2 columns

In [51]:
#The correlation between perGDP vs suicide number
sns.lmplot(x = "perGDP mean",y = "Suicide number",
                 data = combine04)

g = sns.JointGrid(x= "perGDP mean" ,y= "Suicide number", data=combine04)
g = g.plot_joint(plt.scatter,
               color="g",s=40,edgecolor="white")
g=g.plot_marginals(sns.distplot, kde=False, color="g")
rsquare = lambda a,b: stats.pearsonr(a,b)[0]**2
g = g.annotate(rsquare, template="{stat}:{val:.2f}",
              stat="$R^2$",loc= "upper right", fontsize=12)
In [53]:
#Life ex vs suicide
legp = pd.DataFrame(le.groupby(['Country','Year'])['Life expectancy'].sum().unstack())
legp['life mean'] = legp.mean(axis=1)

combine05 = pd.concat([legp,gsdcountryper],axis=1)
combine05 = combine05.ix[:,['life mean','Suicide number']]
combine05 = combine05[~(combine05 == 0).any(axis=1)]
combine05
Out[53]:
life mean Suicide number
Afghanistan 58.19375 NaN
Albania 75.15625 924.76
Algeria 73.61875 NaN
Angola 49.01875 NaN
Antigua and Barbuda 75.05625 179.14
Argentina 75.15625 3894.59
Armenia 73.40000 976.21
Aruba NaN 1596.52
Australia 81.81250 4677.41
Austria 81.48125 9076.23
Azerbaijan 70.73125 356.24
Bahamas 74.28750 344.28
Bahrain 75.72500 467.24
Bangladesh 69.30000 NaN
Barbados 74.35625 891.13
Belarus 69.90625 7831.13
Belgium 80.68125 7900.50
Belize 69.26875 2093.49
Benin 57.56875 NaN
Bhutan 66.16250 NaN
Bolivia (Plurinational State of) 67.70625 NaN
Bosnia and Herzegovina 75.96875 110.81
Botswana 56.05000 NaN
Brazil 73.38125 2174.72
Brunei Darussalam 76.48750 NaN
Bulgaria 72.85000 7016.08
Burkina Faso 55.64375 NaN
Burundi 55.53750 NaN
Cabo Verde 72.51875 133.84
Cambodia 64.34375 NaN
... ... ...
Swaziland 51.32500 NaN
Sweden 82.51875 5247.72
Switzerland 82.33125 4794.07
Syrian Arab Republic 70.85000 NaN
Tajikistan 66.65625 NaN
Thailand 73.08125 2362.67
The former Yugoslav republic of Macedonia 74.11250 NaN
Timor-Leste 64.75625 NaN
Togo 56.66250 NaN
Tonga 72.53125 NaN
Trinidad and Tobago 71.06875 4479.51
Tunisia 74.35625 NaN
Turkey 73.91250 199.17
Turkmenistan 64.61875 2994.73
Uganda 55.70625 NaN
Ukraine 69.93750 8931.66
United Arab Emirates 75.70000 94.89
United Kingdom NaN 2790.92
United Kingdom of Great Britain and Northern Ireland 80.79375 NaN
United Republic of Tanzania 56.00625 NaN
United States NaN 5140.97
United States of America 78.06250 NaN
Uruguay 76.07500 6538.96
Uzbekistan 68.03125 2138.17
Vanuatu 71.38750 NaN
Venezuela (Bolivarian Republic of) 73.38750 NaN
Viet Nam 74.77500 NaN
Yemen 63.86250 NaN
Zambia 53.90625 NaN
Zimbabwe 50.48750 NaN

190 rows × 2 columns

In [54]:
#The correlation between Suicide number vs life
sns.lmplot(x = "life mean",y = "Suicide number",
                 data = combine05)

g = sns.JointGrid(x= "life mean",y= "Suicide number", data=combine05)
g = g.plot_joint(plt.scatter,
               color="g",s=40,edgecolor="white")
g=g.plot_marginals(sns.distplot, kde=False, color="g")
rsquare = lambda a,b: stats.pearsonr(a,b)[0]**2
g = g.annotate(rsquare, template="{stat}:{val:.2f}",
              stat="$R^2$",loc= "upper right", fontsize=12)
In [55]:
#Happiness score
hp = pd.read_csv('2015.csv', index_col = 0, encoding='latin')
hp = pd.DataFrame(hp["Happiness Score"])
hp.head(10)
Out[55]:
Happiness Score
Country
Switzerland 7.587
Iceland 7.561
Denmark 7.527
Norway 7.522
Canada 7.427
Finland 7.406
Netherlands 7.378
Sweden 7.364
New Zealand 7.286
Australia 7.284
In [56]:
#Happiness score vs suicide
combine07 = pd.concat([hp,gsdcountryper],axis=1)
combine07 = combine07.ix[:,['Happiness Score','Suicide number']]
combine07 = combine07[~(combine07 == 0).any(axis=1)]
combine07
Out[56]:
Happiness Score Suicide number
Afghanistan 3.575 NaN
Albania 4.959 924.76
Algeria 5.605 NaN
Angola 4.033 NaN
Antigua and Barbuda NaN 179.14
Argentina 6.574 3894.59
Armenia 4.350 976.21
Aruba NaN 1596.52
Australia 7.284 4677.41
Austria 7.200 9076.23
Azerbaijan 5.212 356.24
Bahamas NaN 344.28
Bahrain 5.960 467.24
Bangladesh 4.694 NaN
Barbados NaN 891.13
Belarus 5.813 7831.13
Belgium 6.937 7900.50
Belize NaN 2093.49
Benin 3.340 NaN
Bhutan 5.253 NaN
Bolivia 5.890 NaN
Bosnia and Herzegovina 4.949 110.81
Botswana 4.332 NaN
Brazil 6.983 2174.72
Bulgaria 4.218 7016.08
Burkina Faso 3.587 NaN
Burundi 2.905 NaN
Cabo Verde NaN 133.84
Cambodia 3.819 NaN
Cameroon 4.252 NaN
... ... ...
South Korea 5.984 NaN
Spain 6.329 3509.06
Sri Lanka 4.271 4658.96
Sudan 4.550 NaN
Suriname 6.269 7162.32
Swaziland 4.867 NaN
Sweden 7.364 5247.72
Switzerland 7.587 4794.07
Syria 3.006 NaN
Taiwan 6.298 NaN
Tajikistan 4.786 NaN
Tanzania 3.781 NaN
Thailand 6.455 2362.67
Togo 2.839 NaN
Trinidad and Tobago 6.168 4479.51
Tunisia 4.739 NaN
Turkey 5.332 199.17
Turkmenistan 5.548 2994.73
Uganda 3.931 NaN
Ukraine 4.681 8931.66
United Arab Emirates 6.901 94.89
United Kingdom 6.867 2790.92
United States 7.119 5140.97
Uruguay 6.485 6538.96
Uzbekistan 6.003 2138.17
Venezuela 6.810 NaN
Vietnam 5.360 NaN
Yemen 4.077 NaN
Zambia 5.129 NaN
Zimbabwe 4.610 NaN

178 rows × 2 columns

In [57]:
#The correlation between Happiness Score vs Suicide number
sns.lmplot(x = "Happiness Score",y = "Suicide number",
                 data = combine07)

g = sns.JointGrid(x= "Happiness Score",y= "Suicide number", data=combine07)
g = g.plot_joint(plt.scatter,
               color="g",s=40,edgecolor="white")
g=g.plot_marginals(sns.distplot, kde=False, color="g")
rsquare = lambda a,b: stats.pearsonr(a,b)[0]**2
g = g.annotate(rsquare, template="{stat}:{val:.2f}",
              stat="$R^2$",loc= "upper right", fontsize=12)
In [58]:
#combine 4 variables
combine08 = pd.concat([legp,perGDP,gsdcountryper,hp],axis=1)
combine08 = combine08.ix[:,['life mean',"perGDP mean",'Suicide number',"Happiness Score"]]
combine08 = combine08[~(combine08 == 0).any(axis=1)]
combine08
Out[58]:
life mean perGDP mean Suicide number Happiness Score
Afghanistan 58.19375 425.455471 NaN 3.575
Albania 75.15625 3218.946571 924.76 4.959
Algeria 73.61875 3737.029476 NaN 5.605
American Samoa NaN 10118.677119 NaN NaN
Andorra NaN 37694.037952 NaN NaN
Angola 49.01875 2943.469412 NaN 4.033
Antigua and Barbuda 75.05625 11926.746118 179.14 NaN
Arab World NaN 4958.009074 NaN NaN
Argentina 75.15625 8447.383895 3894.59 6.574
Armenia 73.40000 2503.337284 976.21 4.350
Aruba NaN 23723.646553 1596.52 NaN
Australia 81.81250 42955.561746 4677.41 7.284
Austria 81.48125 41471.431816 9076.23 7.200
Azerbaijan 70.73125 4017.156756 356.24 5.212
Bahamas 74.28750 NaN 344.28 NaN
Bahamas, The NaN 28782.943463 NaN NaN
Bahrain 75.72500 19352.308916 467.24 5.960
Bangladesh 69.30000 663.431090 NaN 4.694
Barbados 74.35625 14836.299957 891.13 NaN
Belarus 69.90625 4595.204594 7831.13 5.813
Belgium 80.68125 38897.674876 7900.50 6.937
Belize 69.26875 4182.276074 2093.49 NaN
Benin 57.56875 680.386441 NaN 3.340
Bermuda NaN 78023.047081 NaN NaN
Bhutan 66.16250 1687.023703 NaN 5.253
Bolivia NaN 1756.938185 NaN 5.890
Bolivia (Plurinational State of) 67.70625 NaN NaN NaN
Bosnia and Herzegovina 75.96875 3707.447219 110.81 4.949
Botswana 56.05000 5474.333814 NaN 4.332
Brazil 73.38125 7584.374281 2174.72 6.983
... ... ... ... ...
Tonga 72.53125 3100.254914 NaN NaN
Trinidad and Tobago 71.06875 14416.434607 4479.51 6.168
Tunisia 74.35625 3519.372499 NaN 4.739
Turkey 73.91250 8516.238539 199.17 5.332
Turkmenistan 64.61875 3623.092927 2994.73 5.548
Turks and Caicos Islands NaN NaN NaN NaN
Uganda 55.70625 447.300367 NaN 3.931
Ukraine 69.93750 2357.270897 8931.66 4.681
United Arab Emirates 75.70000 38286.938667 94.89 6.901
United Kingdom NaN 39775.770878 2790.92 6.867
United Kingdom of Great Britain and Northern Ireland 80.79375 NaN NaN NaN
United Republic of Tanzania 56.00625 NaN NaN NaN
United States NaN 46327.529934 5140.97 7.119
United States of America 78.06250 NaN NaN NaN
Upper middle income NaN 4950.183263 NaN NaN
Uruguay 76.07500 9494.258576 6538.96 6.485
Uzbekistan 68.03125 1085.305478 2138.17 6.003
Vanuatu 71.38750 2357.943548 NaN NaN
Venezuela NaN NaN NaN 6.810
Venezuela (Bolivarian Republic of) 73.38750 NaN NaN NaN
Venezuela, RB NaN 8606.119732 NaN NaN
Viet Nam 74.77500 NaN NaN NaN
Vietnam NaN 1091.045279 NaN 5.360
Virgin Islands (U.S.) NaN 37293.180517 NaN NaN
West Bank and Gaza NaN 1966.481465 NaN NaN
World NaN 8350.054503 NaN NaN
Yemen 63.86250 NaN NaN 4.077
Yemen, Rep. NaN 1059.250861 NaN NaN
Zambia 53.90625 1071.032426 NaN 5.129
Zimbabwe 50.48750 724.342080 NaN 4.610

300 rows × 4 columns

In [59]:
#Correlation between 4 variables
correlation= combine08.corr()
plt.figure(figsize=(10,8))
ax = sns.heatmap(correlation, vmax=1, square=True, annot=True,fmt='.2f', 
                 cmap ='GnBu', cbar_kws={"shrink": .5}, robust=True)
plt.title('Correlation between the features', fontsize=20)
plt.show()
In [60]:
#Correlation between 4 variables
pd.scatter_matrix(combine08, figsize=(8, 8))
plt.show()
In [61]:
#The correlation between Happiness score vs Life expectancy
sns.lmplot(x = "life mean",y = "Happiness Score",
                 data = combine08)

g = sns.JointGrid(x= "Happiness Score",y= "life mean", data=combine08)
g = g.plot_joint(plt.scatter,
               color="g",s=40,edgecolor="white")
g=g.plot_marginals(sns.distplot, kde=False, color="g")
rsquare = lambda a,b: stats.pearsonr(a,b)[0]**2
g = g.annotate(rsquare, template="{stat}:{val:.2f}",
              stat="$R^2$",loc= "upper right", fontsize=12)
In [ ]: